﻿function load_type3() {
    var obj = document.getElementById("device_type3");

    document.getElementById("device_type3").options.length = 0;
    $.ajax({
        url: "Ajax/QueryDevice.aspx?typedevice=gettype",
        type: "post",
        dataType: "json",
        data: {},
        success: function (msg) {
            $(msg).each(function () {
                var option;
                var txt = this.name
                var val = this.id;
                option = new Option(txt, val);
                obj.options.add(option);
            })

        }
    })

}
var number_du;
$("decument").ready(function () {
    load_type3();
    $("#du_download").hide();
    number_du = 0;
    $("#du_query").mouseup(function () {
        var du_begin_time = $("#du_begin").val();
        var du_end_time = $("#du_end").val();
        var device_type = $("#device_type3").val();
        if (du_end_time < du_begin_time) {
            alert("请输入正确的起始时间");

        }
        else {
            $.ajax({
                url: "Ajax/QueryDevice.aspx?typedevice=du_query",
                type: "post",
                dataType: "json",
                data: { begin_time: du_begin_time, end_time: du_end_time, type_id: device_type },
                success: function (msg) {

                    $("table#du_table tr:gt(0)").remove();
                    $(msg).each(function () {
                        var id = this.id;
                        var deivce_name = this.name;
                        var from = this.timeFrom;
                        var to = this.timeTo;
                        var user_ID = this.userID;
                        var typeName = this.typeName;
                        var row = "<tr class='record_row' id='" + number_du + "_du'><td align='center'>" + this.id + "</td><td align='center'>" + this.device_name + "</td><td align=center>" + this.typeName + "</td><td align=center>" + this.timeFrom + "</td><td align=center>" + this.timeTo + "</td><td align=center>" + this.userID + "</td></tr>";
                        var row_num = $("table#du_table tr").length - 1;
                        $(row).insertAfter($("table#du_table tr:eq(" + row_num + ")"));
                        $("#du_download").show();
                    })

                }
            })
        }
    })
    $("#du_download").mouseup(function () {
        
        var du_begin_time = $("#du_begin").val();
        var du_end_time = $("#du_end").val();
        var device_type = $("#device_type3").val();
        window.open("/download.aspx?begin_time="+du_begin_time+"&end_time="+du_end_time+"&type_id="+device_type);
//        $.ajax({
//            url: "Ajax/QueryDevice.aspx?typedevice=du_download",
//            type: "post",
//            dataType: "json",
//            data: { begin_time: du_begin_time, end_time: du_end_time, type_id: device_type },
//            success: function (msg) {
//                alert("下载");
//            }
//        })
    })
})